package com.le.tester.book.concurrentjavafight.l_11_4;

import java.util.Set;

/**
 * createTime：2023/2/4 14:11
 * description：对锁进行分解，那么在使用的时候，显示锁住的代码快不应该是直接的锁住方法
 */
public class ServerStatusPlus {

    public final Set<String> users;

    public final Set<String> queries;

    public ServerStatusPlus(Set<String> users, Set<String> queries) {
        this.users = users;
        this.queries = queries;
    }

    public void addUser(String u) {

        //锁住一个常量
        synchronized (users) {
            users.add(u);
        }
    }

    public void addQuery(String q) {
        synchronized (queries) {
            queries.add(q);
        }
    }
}
